{{- $version := "4.4" }}
---
artifact: {{ .ModuleName }}/build-chrony-static-artifact
from: {{ .Images.BASE_ALPINE_DEV }}
shell:
  install:
    - mkdir /src
    - cd /src
    - git clone --depth 1 --branch {{ $version }} {{ $.SOURCE_REPO }}/chrony/chrony.git .
    - echo "{{ $version }}" > version.txt
    - CFLAGS="-static" LDFLAGS="-static" ./configure --prefix=/opt/chrony-static
    - make -j1
    - make -j1 install
    - chown -R 64535:64535 /opt/chrony-static
    - chmod 0700 /opt/chrony-static/bin/chronyc
    - chmod 0700 /opt/chrony-static/sbin/chronyd
---
artifact: {{ .ModuleName }}/build-entrypoint-artifact
from: {{ .Images.BASE_GOLANG_20_ALPINE }}
git:
  - add: /{{ $.ModulePath }}modules/470-{{ $.ModuleName }}/images/{{ $.ImageName }}/
    to: /src
    includePaths:
      - '**/*.go'
      - '**/*.mod'
      - '**/*.sum'
    stageDependencies:
      install:
        - '**/*.go'
        - 'go.mod'
        - 'go.sum'
mount:
  - fromPath: ~/go-pkg-cache
    to: /go/pkg
shell:
  install:
    - cd /src
    - GOPROXY={{ $.GOPROXY }} CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags='-extldflags "-static" -s -w' -o entrypoint main.go
    - chown -R 64535:64535 entrypoint
    - chmod 0700 entrypoint
---
image: {{ .ModuleName }}/{{ .ImageName }}
fromImage: common/distroless
import:
  - artifact: {{ .ModuleName }}/build-chrony-static-artifact
    add: /opt/chrony-static
    before: setup
  - artifact: {{ .ModuleName }}/build-chrony-static-artifact
    add: /sbin/tini-static
    to: /tini
    before: setup
  - artifact: {{ .ModuleName }}/build-entrypoint-artifact
    add: /src/entrypoint
    to: /entrypoint
    before: setup
docker:
  ENTRYPOINT: ["/tini", "--"]
  CMD: ["/entrypoint"]
